package de.hatraco.funderberg.blackjack.utils;

import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

public class MaxDoc extends PlainDocument {
	
	private int max;
	
	public MaxDoc(int max) {
	super();
	this.max = max;
	}
	
	public void insertString (int offset, String s, AttributeSet as){
		if (s == null) return;
		if ((getLength() + s.length()) <= max) {
			try {
				super.insertString(offset, s, as);
			} 
			catch (BadLocationException e) {
				e.printStackTrace();
			}
		}
	}
}
